package com.reggie.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.reggie.acl.dataobject.DishFlavor;
import com.reggie.acl.mapper.DishFlavorMapper;
import com.reggie.service.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 菜品口味关系表 服务实现类
 * </p>
 *
 * @author yth
 * @since 2023-02-04
 */
@Service
public class DishFlavorServiceImpl implements DishFlavorService {

    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    @Override
    public void save(Collection<DishFlavor> dishFlavors) {
        // TODO 待优化
        for (DishFlavor dishFlavor : dishFlavors) {
            dishFlavorMapper.insert(dishFlavor);
        }
    }

    @Override
    public void removeBatchDishIds(Collection<Long> ids) {
        LambdaQueryWrapper<DishFlavor> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(DishFlavor::getDishId, ids);
        dishFlavorMapper.delete(wrapper);
    }

    @Override
    public List<DishFlavor> getByDishId(long dishId) {
        LambdaQueryWrapper<DishFlavor> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DishFlavor::getDishId, dishId);
        return dishFlavorMapper.selectList(wrapper);
    }

    @Override
    public List<DishFlavor> getByDishIds(Collection<Long> dishIds) {
        LambdaQueryWrapper<DishFlavor> wrapper = Wrappers.lambdaQuery(DishFlavor.class);
        wrapper.in(DishFlavor::getDishId, dishIds);
        return dishFlavorMapper.selectList(wrapper);
    }

}
